{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python \t\t3.6\n",
      "Tensorflow \t1.0.0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Keras \t\t2.0.3\n"
     ]
    }
   ],
   "source": [
    "import sys; print('Python \\t\\t{0[0]}.{0[1]}'.format(sys.version_info))\n",
    "import tensorflow as tf; print('Tensorflow \\t{}'.format(tf.__version__))\n",
    "import keras; print('Keras \\t\\t{}'.format(keras.__version__))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline \n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting ../mnist-data/train-images-idx3-ubyte.gz\n",
      "Extracting ../mnist-data/train-labels-idx1-ubyte.gz\n",
      "Extracting ../mnist-data/t10k-images-idx3-ubyte.gz\n",
      "Extracting ../mnist-data/t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "mnist = input_data.read_data_sets(\"../mnist-data/\", one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(55000, 784)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mnist.train.images.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA2oAAABpCAYAAABLV9A4A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G+\n709/+hMAzrnKDkxEas5dd90FwOjRo33fpEmTANhxxx2rMiYRadp3330HwI033uj7Xnklt+bBs88+\n69vbb7903962bdv6Pnvet2nTxvd16NAh7mBbmbvvXlok8NJLL/V9VtxN2Uo5rLfeejl977zzThVG\nUhzNqImIiIiIiKSMDtRERERERERSpsUtfbz88st9e6WVVgJgzJgxvm+FFVrcXa66N954A4ARI0b4\nvrffftu3bfnJxx9/7PvuvfdeAM477zzf16lTp7KOU6S57rjjDgDmzp3r++xxPnv27KqMSaS1C09x\nWLhwIQB/+ctffN9hhx0GwNChQ5u8nh122MG3J06cCEBdXZ3vmzZtGgCzZs3yfccddxwAxx9/vO+z\nzxqS3zPPPOPbw4YNA2CfffbxfSuuuGKlhyStyLx58wBYd911qzyS4mhGTUREREREJGVa3PSSFQsB\nOOqoo4Dsb8gkjldffdW3Bw0aBGSfnJkkiW8PGDAAgI022sj32WzEzJkzfd/DDz8MQMeOHcsw4vSy\nb4TXXHNN32czv4sXL/Z9H3zwQc7vPv7447793HPPNXobV111lW+vvfbaOZf/+c9/BmC//fYrdNit\nwvTp06s9hKr47LPPAPjDH/7g+8IZi6b8+Mc/9u2LL74YgPXXXz/i6KQ1+fzzz33b3jfOPPNM3zd5\n8uSc37nkkksA6Nu3r++zWba33nrL92222Wa+bbNrW265pe974oknADj88MN9n82yLViwwPddcMEF\ngGbWlnXfffcBcMUVV/i+//znPwCstdZavq+15vbRRx8Bmc8+AOPGjQOyt5AK/fa3vwVg/PjxZR5d\nbbMCNZB5btvztDnComFWoND+BpWiGTUREREREZGU0YGaiIiIiIhIyrSYpY92cvHXX3/t+3r27Fmt\n4bRYJ554IgCPPvqo77Mlj127dvV94TK+F198EYAjjzzS99mJ23YZwI9+9CMgs7QEYOWVV4429mqx\n+wrZSxzMY489BmRPsdtSEFsaEf5cKFxi2tTegOHPvfnmmzmX2xKftC99vPXWWwG4+eabfd9ZZ50F\nQK9evSoyBltC1dI89dRTvj1y5EgAXnvtNd+X7/G10047AfD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oVSbLkoLK2m1BjbGw1gn332AbC14TlseWh4Yvzll19e/GDzSGOm5WTFgsJlz2HR\nghhaW6aFsiW6TT0/mpIn117OucG0klz32GOP6NdZjUw7dOjg22effTaQWRIfOvHETP0CWwYZFqGy\nolhhAbCLL74YgB133NH3hUUECl0mHr6eN9eymb7xxhuk8XFqS5DDPezs72GFKyCzNN/er6qhtb2m\nWhGmr776yveFf5MYWkOm8+bNy2mntahIIVUfnwIaK3kW/92hFejXr19OxTPn3KdJknyEMi2KMo1P\nmcanTMtj2Vydc7OTJLFvgZRrEZRpfMtm2qdPH2bMmKFMS6DX1PiUaboU9/WltFjhSen2rWV40qqV\nLp4/f77vs4ILYeGL8Elu31RaoRaAX//610Bps2hpN3bsWACeffZZ3zdgwAAAFixY4Pvsm+B7773X\n933xxRdAdll4m7mETGGWfv36xR52q7fLLrv49qOPPgpkzyBLfEuWLAHgu+8y56vHKNjUUoQFMJ54\n4gkANt10U99X6nYpadGmTRvftvef8D3i7bffBjLbuwBssMEGOT9n70XhY2jFFVcsw4hbJsvK3sMg\n8xgMi6hUcyatNendu7dvT5s2rYojqW077LCDb4efYdNO74QiIiIiIiIpowM1ERERERGRlNHSR2lU\nx44dAZgwYYLvs7YtvwFs086swgvhMkc7GTU8ibs12GSTTYDs5SO2ZCdc0pjPyiuvDGTvaxdeTyl7\nzUnThg0blrctcay11lo5fVOnTgWy9wvacMMNKzWk1Hv55Zd924oIhEsfiy3Ckma2DHLQoEE5lx19\n9NGVHk6rd9FFF1V7CK1W+Fw39vkMYP3116/kcGrW008/Xe0hFEUzaiIiIiIiIinT8r6Gk4ro379/\nTt/AgQOrMJL0uuyyy4BMqWOAe+65B8guu28zb4MHD/Z9Y8aMAaCurq7cwxSpqAsvvBCA+vp639ej\nRw8gveWRq+2FF17I6cs30yQiLc/BBx/s29dccw0AZ511lu/beOONKz4mqRzNqImIiIiIiKSMDtRE\nRERERERSRksfRcqkXbt2AJx++um+L2yLtEYdOnQAMnvUSfNYkZWRI0d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y+ac84B1wCvJklyQXDR3cDQ\nhvZQ4B8VHpoyjU+ZxlezmUJqc1Wm8SnT+JRpfMq0PGo2V2UaX6oyjVWVpJD/gMEsrZwyBzilkrdd\n4rj7sXR680XghYb/BgNrAo8AbwIPA2tUYWzKVJkq01aYqzJVpspUmSpT5apMW3amrmFAIiIiIiIi\nkhIqJiIiIiIiIpIyOlATERERERFJGR2oiYiIiIiIpIwO1ERERERERFJGB2oiIiIiIiIpowM1ERER\nERGRlNGBmoiIiIiISMr8PzT+1wrcrWcKAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x11bc75438>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15,5))\n",
    "for i in list(range(10)):\n",
    "    plt.subplot(1, 10, i+1)\n",
    "    pixels = mnist.test.images[i+100]\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import tensorlayer as tl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Set parameters\n",
    "training_iteration = 10\n",
    "batch_size = 500\n",
    "display_step = 2\n",
    "\n",
    "FLAGS = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# TF graph input\n",
    "x = tf.placeholder('float', [None, 784]) # mnist data image of shape 28*28=784\n",
    "y = tf.placeholder('float', [None,10]) # 0-9 digits recognition => 10 classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  [TL] InputLayer  input_layer: (?, 784)\n",
      "  [TL] DenseLayer  output_layer: 10 softmax\n"
     ]
    }
   ],
   "source": [
    "network = tl.layers.InputLayer(x, name='input_layer')\n",
    "network = tl.layers.DenseLayer(network, n_units=10,act = tf.nn.softmax, name='output_layer')\n",
    "\n",
    "y_hat = network.outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "with tf.name_scope(\"cost_function\") as scope:\n",
    "    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=y_hat,labels=y))\n",
    "    tf.summary.scalar(\"cost_function\", cost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_params = network.all_params\n",
    "with tf.name_scope(\"train\") as scope:\n",
    "    # Gradient descent\n",
    "    optimizer = tf.train.AdamOptimizer()\n",
    "    learn     = optimizer.minimize(cost, var_list=train_params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initializing the variables\n",
    "init = tf.global_variables_initializer()\n",
    "\n",
    "# Merge all summaries into a single operator\n",
    "merged_summary_op = tf.summary.merge_all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Launch the graph\n",
    "sess = tf.InteractiveSession()\n",
    "\n",
    "# Logs and graph for tensorboard\n",
    "summary_writer = tf.summary.FileWriter('./tensorboard/tl', graph=sess.graph)\n",
    "\n",
    "sess.run(init)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Test the model, Calculate accuracy\n",
    "prediction = tf.equal(tf.argmax(y_hat, 1), tf.argmax(y, 1))\n",
    "acc = tf.reduce_mean(tf.cast(prediction, tf.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Start training the network ...\n",
      "Epoch 1 of 10 took 0.255398s\n",
      "   val loss: 1.760382\n",
      "   val acc: 0.814800\n",
      "Epoch 2 of 10 took 0.234566s\n",
      "   val loss: 1.659706\n",
      "   val acc: 0.871000\n",
      "Epoch 3 of 10 took 0.232309s\n",
      "   val loss: 1.624177\n",
      "   val acc: 0.890400\n",
      "Epoch 4 of 10 took 0.232735s\n",
      "   val loss: 1.606006\n",
      "   val acc: 0.899500\n",
      "Epoch 5 of 10 took 0.230277s\n",
      "   val loss: 1.594066\n",
      "   val acc: 0.904700\n",
      "Epoch 6 of 10 took 0.232189s\n",
      "   val loss: 1.585544\n",
      "   val acc: 0.908300\n",
      "Epoch 7 of 10 took 0.232217s\n",
      "   val loss: 1.579591\n",
      "   val acc: 0.910300\n",
      "Epoch 8 of 10 took 0.232132s\n",
      "   val loss: 1.574692\n",
      "   val acc: 0.911700\n",
      "Epoch 9 of 10 took 0.233179s\n",
      "   val loss: 1.570638\n",
      "   val acc: 0.913800\n",
      "Epoch 10 of 10 took 0.232514s\n",
      "   val loss: 1.567255\n",
      "   val acc: 0.915800\n",
      "Total training time: 2.626965s\n"
     ]
    }
   ],
   "source": [
    "# train the network\n",
    "tl.utils.fit(sess, network, learn, cost, mnist.train.images, mnist.train.labels, x, y,\n",
    "             acc=acc, batch_size=500, n_epoch=10, print_freq=1, \n",
    "             X_val=mnist.test.images, y_val=mnist.test.labels, eval_train=False)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Start testing the network ...\n",
      "   test acc: 0.915800\n"
     ]
    }
   ],
   "source": [
    "# evaluation\n",
    "tl.utils.test(sess, network, acc, mnist.test.images, mnist.test.labels, x, y, batch_size=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 0.0002838799,\n",
       " 1: 2.0632886e-05,\n",
       " 2: 0.0062525244,\n",
       " 3: 5.8651021e-05,\n",
       " 4: 0.00042876235,\n",
       " 5: 7.0531462e-07,\n",
       " 6: 0.99214077,\n",
       " 7: 3.4034816e-05,\n",
       " 8: 0.00065167487,\n",
       " 9: 0.00012842476}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# test item #100 is a \"six\"\n",
    "pixels = mnist.test.images[100]\n",
    "\n",
    "result = sess.run(y_hat, feed_dict={x:[pixels]})\n",
    "dict(zip(range(10), result[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def test_render(pixels, result, truth):\n",
    "    #pixels, result and truth are np vectors\n",
    "    plt.figure(figsize=(10,5))\n",
    "    plt.subplot(1, 2, 1)\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "\n",
    "    plt.subplot(1, 2, 2)\n",
    "    \n",
    "    #index, witdh\n",
    "    ind = np.arange(len(result))\n",
    "    width = 0.49\n",
    "\n",
    "    plt.barh(ind,result, width, color='orange', edgecolor='k', hatch=\"/\")\n",
    "    plt.barh(ind+width,truth,width, color='g', edgecolor='k')\n",
    "    plt.yticks(ind+width, range(10))\n",
    "    plt.margins(y=0)\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAEyCAYAAADeAVWKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHFlJREFUeJzt3X2QXXWd5/HPJw88NgMIMdMbEoLAWJNlx4RqgVlAcAAL\nWAt8YATEGUSKlqowPKy1LiNrgQOjMioylo7awSwsy4M8m5plFGTIMljK0MEIIYGRYQIkNkmUQWit\nJZD+7h/3AE2b7nO6z733d06f96u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wPBo8xoXyKvhgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1255b9d68>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import random\n",
    "i = random.randint(0,mnist.test.images.shape[0])\n",
    "\n",
    "pixels = mnist.test.images[i]\n",
    "truth  = mnist.test.labels[i]\n",
    "result = sess.run(y_hat, feed_dict={x:[pixels]})[0]\n",
    "\n",
    "test_render(pixels, result, truth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Close the Session when we're done.\n",
    "# sess.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
